import java.io.File;
import java.io.IOException;

import org.springframework.context.support.ClassPathXmlApplicationContext;

import com.szkjt.model.Staff;
import com.szkjt.service.StaffService;

import jxl.Sheet;
import jxl.Workbook;
import jxl.read.biff.BiffException;

public class Test1 {

	public static void main(String[] args) throws IOException, BiffException {
		Test1 test1 = new Test1();
		test1.importUser();
	}
	
	public void importUser() throws IOException, BiffException {
		String[] springXml = {"spring_core.xml", "spring_activiti.xml"};
		ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext(springXml);	
		StaffService staffService = (StaffService)context.getBean("staffService");
		
		Workbook workbook = Workbook.getWorkbook(new File("f:/user.xls"));
		Sheet sheet = workbook.getSheet(0);
		for(int i = 1; i < sheet.getRows(); i++) {
			String name = sheet.getCell(0, i).getContents();
			String eMail = sheet.getCell(1, i).getContents();
			String pwd = sheet.getCell(2, i).getContents();
			String pictureId = sheet.getCell(3, i).getContents();
			
			Staff staff = new Staff();
			staff.setName(name);
			staff.setEMail(eMail);
			staff.setPassword(pwd);
			staff.setImageName(pictureId);
			
			staffService.saveOrUpdate(staff);
		}
	}
}
